from qiniu import Auth, put_data
access_key = "BrFm0TWI-ZyzbS71NPMqqxJj8v2oKaam25RAs5M3"
secret_key = "aNLf_9LbDXpq2H7oyils49e5hIKOOiY_6Zts07Mu"
bucket_name = "ihome"


def storage(data):
    # 进行网络操作的，所以要try
    try:
        q = Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        ret, info = put_data(token, None, data)
        print(ret, info)
    except Exception as e:
        raise e;

    if info.status_code != 200:
        raise Exception("上传图片失败")
    return ret["key"]

if __name__ == "__main__":
    file = input("请输入文件路径")
    with open(file, "rb") as f:
        storage(f.read())

